//organization_characteristic_course
exports.organization_characteristic_course = function (req, res) {

    //获取restful参数
    var restfulParams = req.routeInfo.restfulParams;

    //最终结果
    var resultData = {};

    var organizationData = 0;

    var skip = restfulParams.skip == undefined ? 0 : restfulParams.skip;

    var limit = restfulParams.limit == undefined ? config.publicConfig.LIMIT : restfulParams.limit;

    // + "/skip/" + skip + "/limit/" + limit
    //任务流创建
    async.waterfall([
            function (cb) {

                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.searchOrganization + "/o_id/" + restfulParams.o_id,
                        method: 'POST',
                        data: {
                            fields: ["o_id", "o_name", "o_logo", "o_browse_times", "o_course_sales", "o_slogan", "o_desc", "o_address", "o_provinces", "o_city", "o_area", "o_create_time", "o_tags", "o_star_level", "o_longitude", "o_latitude", "o_phone", "is_cashback", "cashback_money"].join(",")
                        }
                    },
                    function (err, data) {
                        //判断是否有错误信息
                        if (err) {
                            return cb(err, data);
                        }
                        // console.log(222222);
                        organizationData = data.data[0];

                        cb();
                    }
                );
            },
            function (cb) {

                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.search_organization_course + "/oc_oid/" + restfulParams.o_id + "/oc_type/0/sort_order/oc_order-asc"+ "/skip/" + skip + "/limit/" + limit,
                        method: 'POST',
                        data: {
                            fields: ["oc_id", "oc_title", "oc_title_image", "oc_new_price", "oc_age", "oc_count", "oc_course_count", "oc_sales_volume"].join(",")
                        }
                    },
                    function (err, data) {
                        //判断是否有错误信息
                        if (err) {
                            return cb(err, data);
                        }

                        resultData.organizationCourseData = data.data;

                        if (organizationData.is_cashback == 1) {

                            for (var i = 0; i < resultData.organizationCourseData.length; i++) {

                                if (parseFloat(resultData.organizationCourseData[i].oc_new_price) > parseFloat(organizationData.cashback_money)) {
                                    resultData.organizationCourseData[i].is_cashback = true;
                                } else {
                                    resultData.organizationCourseData[i].is_cashback = false;
                                }

                            }

                            cb();

                        } else {
                            cb();
                        }


                    }
                );

            }
        ], function (err, result) {

            RES.response(res, true, resultData);

        }
    );

};